<script type="text/javascript">
function autoCompletion(j) {
	$('#dn-' + j).autocomplete(${(type)!'[]'}, {
		max: 12,    //列表里的条目数
		minChars: 0,    //自动完成激活之前填入的最小字符
		width: 220,     //提示的宽度，溢出隐藏
        scrollHeight: 300,   //提示的高度，溢出显示滚动条
        matchContains: true,    //包含匹配，就是data参数里的数据，是否只要包含文本框里的数据就显示
        autoFill: false,    //自动填充
        formatItem: function(row, i, max) {
      	  return i + '/' + max + ':"' + row.dn + '"';
        },
        formatMatch: function(row, i, max) {
      	  return row.dn + row.dc;
        },
        formatResult: function(row) {
      	  return row.dn;
		}
	}).result(function(event, row, formatted) {
		$('#dc-' + j).val(row.dc);
	});
}


function countCheckV(i,btn) {
	var count = $('#count_' + i).val();
	var ch_count = $('#check_count_' + i);
	var j = btn.attr('j');
	var old = parseInt(ch_count.html());
	var num = 0;
	var _dc = $('input#dc-' + j);
	var _dn = $('input#dn-' + j);
	var _skm = $('input#skm-' + j);
	
	if ('checked' == btn.attr('checked') || btn.attr('checked')) {
		_dn.show();
		_dc.attr('name',_dc.attr('p'));
		_skm.show();
		_skm.attr('name',_skm.attr('p'));
		num = old + 1;
		if (count < num) {
			sys_msg("不能超过申请数量哦！");
			btn.removeAttr('checked');
			_dn.hide();
			_dc.removeAttr('name');
			_skm.hide();
			_skm.removeAttr('name');
			return false;
		}
	} else {
		_dn.hide();
		_dc.removeAttr('name');
		_skm.hide();
		_skm.removeAttr('name');
		num = old - 1;
		if (num < 0)
			num = 0;
	}
			
	ch_count.html(num);
}
// 全选
function checkAll (btn,i) {
	var count = $('#count_' + i).val();
	var check = btn.attr('checked');
	var cla = "check-i-" + i;
	var num = 0;
	var ch_count = $('#check_count_' + i);
	var ok = false;
	$('input.' + cla).each(function (e) {
		if ('checked'== check || check) {
			$(this).attr('checked','checked');
			num++;
			if (count < num) {
				sys_msg("不能超过申请数量哦！");
				$('input.' + cla).removeAttr('checked');
				return false;
			}
			ok = true;
		} else {
			ok = false;
			$(this).removeAttr('checked');
		}
	});
	// 给选中的加上name 属性
	var vaList = $('#vaList_' + i);
	if (ok) {
		vaList.find('input.dn').each(function () {
			$(this).show();
		});
		vaList.find('input.dc').each(function () {
			$(this).attr('name',$(this).attr('p'));
		});
		vaList.find('input.skm').each(function () {
			$(this).show();
			$(this).attr('name',$(this).attr('p'));
		});
	} else {
		vaList.find('input.dn').each(function () {
			$(this).hide();
		});
		vaList.find('input.dc').each(function () {
			$(this).removeAttr('name');
		});
		vaList.find('input.skm').each(function () {
			$(this).hide();
			$(this).removeAttr('name');
		});
	}
	ch_count.html(num);
}
</script>
                                                                                        
<div class="row-fluid">
	<div class="span8">
		<div>
			<form id="editVehicleForm">
			
				<table style="width:100%;" class="table table-bordered">
					<thead>
						<tr>
							<th>车辆类型</th>
							<th colspan="3">申请数量&nbsp;/&nbsp;指派数量</th>
						</tr>
					</thead>
					<#assign i = 0/>
					<#assign j = 0/>
					<#if apply.adList?? && (apply.adList?size gt 0)>
					<input name="list[${j}].vac" value="${(apply.code)!''}" type="hidden" />
					<#list apply.adList as item>
					<tr class="rep">
						<td>${(item.vtn)!''}<input name="adList[${i}].vtc" value="${(item.vtc)!''}" type="hidden" /></td>
						<td style="font-size:large;" colspan="3">${(item.count)!''} / <font id="check_count_${i}" style="color:green;">0</font></td>
						<input value="${(item.count)!''}" type="hidden" id="count_${i}"/>
					</tr>
					<tr>
						<td colspan="5" class="td-rep" style=";">
							<div id="vaList_${i}">
								<table class="table table-bordered" >
									<tr><th colspan="4" style="text-align:center;">当前空闲车辆</th></tr>
									<tr>
										<th style="width:20px;"><input type="checkbox" class="check-all" onclick="javascript:checkAll($(this),${i});"/></th>
										<th style="width:30%;">车牌号</th>
										<th>司机</th>
										<th>当前公里数</th>
									</tr>
									<#if item.vehicleList??>
									<#list item.vehicleList as v>
									<tr class="v-rep">
										<td><input type="checkbox" name="list[${j}].plate" class="check-i-${i} check-j-${j}" value="${v.plate}" j="${j}" onclick="javascript:countCheckV(${i},$(this));" /></td>
										<td>${(v.plate)!''}<input name="list[${j}].vc" value="${v.code}" type="hidden"/></td>
										<td>
											<input type="text" style="width:120px;display:none;" class="dn" id="dn-${j}" p="list[${j}].dn" onclick="javascript: autoCompletion(${j});"/>
											<input type="hidden" class="dc" id="dc-${j}" p="list[${j}].dc" />
										</td>
										<td><input type="text" style="width:80px;display:none;" class="skm" id="skm-${j}" p="list[${j}].skm"/></td>
									</tr>
									<#assign j = j + 1/>
									</#list>
									<#else>
									<tr>
										<td colsapn="4" style="color:red;">没有空闲的车辆!!</td>
									</tr>
									</#if>
								</table>
							</div>
						</td>
					</tr>
					<#assign i =  i + 1/>
					</#list>
					</#if>
					<tr>
						<th>确认人:&nbsp;${(apply.cn)!''}<input name="cn" value="${(apply.cn)!''}" type="hidden" id="cn"/><input name="cu" value="${(apply.cu)!''}" type="hidden" id="user"/></th>
						<th>密码:&nbsp;<input name="pwd" id="pwd" type="password"/><a class="btn btn-waring btn-xs" onclick="javascript: affirm_vehicle(); return false;">验证</a></th>
					</tr>
					<tr height="40">
						<td colspan="5" style="text-align: center;">
							<a href="javascript:;" class="btn btn-info" onclick="javascript: saveAssign_vehicle(); return false;"><i class="icon-save"></i>&nbsp;保&nbsp;&nbsp;存</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<a href="javascript:;" class="btn btn-primary" onclick="javascript: sys_load_handle('vehicle');return false;"><i class="fontello-icon-block"></i>&nbsp;取&nbsp;&nbsp;消</a>
						</td>
					</tr>
				</table>
				<#assign i =  i + 1/>
			</form>
		</div>
	</div>
</div>
<div id="tempList" style="display:none;">
	<div class="filter-table rep" style="margin-left:5px; margin-bottom:0px;">
		<input class="pc" type="hidden"/>
		<button type="button" class="close" data-dismiss="alert" onclick="javascript:deleteSelectedItem($(this));">&times;</button>
		<a class="title" href="#"></a>
		<div class="input-append">
			<input class="cn" type="text"/>
			<button class="btn btn-xs btn-primary" pib="${i}" type="button" onclick="javascript:selectUser_vehicle($(this));return false;"><i class="icon-search"></i></button>
			<input class="cu" type="hidden"/>
		</div>
		<input class="skm" type="text"/>
	</div>
</div>